#include<bits/stdc++.h>
using namespace std;
int n,dep[2005],T,tc,m,ans;
bool vis[2005];
vector<int>e[2005];
void dfs(int cur,int fa){
	dep[cur]=dep[fa]+1,vis[cur]=1;
	for(int x:e[cur])
		if(x!=fa){
			if(vis[x])
				ans=min(ans,abs(dep[cur]-dep[x]));
			else
				dfs(x,cur);
		}
}
int main(){
	freopen("oi.in","r",stdin),freopen("oi.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cin>>tc>>T;
	while(T--){
		cin>>n>>m,ans=0x3f3f3f3f;
		for(int i=1;i<=n;i++)
			e[i].clear(),vis[i]=0;
		for(int i=1,u,v;i<=m;i++)
			cin>>u>>v,e[u].emplace_back(v),e[v].emplace_back(u);
		for(int i=1;i<=n;i++)
			if(!vis[i])
				dfs(i,0);
		cout<<1-m-ans<<' '<<ans<<'\n';
	}
	return 0;
}